<script setup lang="ts">
import { onMounted } from 'vue';
import { state } from './state';
import { getCurrentInstance, showToast } from '@tarojs/taro';
import { SYS_REGION_LIST } from '/@/api/modules/base/sys-region';
import { UPDATE_AREA } from '/@/api/modules/base/sys-user';
/**
 * @description 当前路由信息
 */
const params = getCurrentInstance().router?.params as unknown as {
  id: string;
};

//根据id查询详情信息
function queryDetail(page: number = 1, pageSize: number = 15) {
  if (!params.id) {
    showToast({ title: '空间定位失败', icon: 'error' });
    return;
  }
  SYS_REGION_LIST({
    comQuery: { page, pageSize },
    id: params.id,
  }).then((res) => {
    if (!res.content || !res.content.length) return;
    state.item = res.content[0];
    UPDATE_AREA({ areaId: state.item.id, areaName: state.item.name });
  });
}

onMounted(() => {
  queryDetail();
});
</script>

<template>
  <view class="scan-workspace app-page--1">
    <app-navbar title="空间定位" />
    <scroll-view class="app-page__wrapper" :scroll-y="true" :lower-threshold="100">
      <view class="scan-workspace_wrapper">
        <view class="scan-workspace__position">
          <text>{{ state.item.name }}</text>
        </view>
        <view class="scan-workspace__tip"><text>已将您的位置更新至当前地点</text></view>
      </view>
    </scroll-view>
  </view>
</template>

<style lang="scss">
@import './index.scss';
</style>
